home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / AppleScanGS / xSaveFile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-06  |  14.1 KB  |  442 lines  |  [TEXT/MPS ]

  1. #include <gsos.h>
  2. #include <memory.h>
  3. #include <malloc.h>
  4. #include <string.h>
  5. #include <quickdraw.h>
  6. #include <qdaux.h>
  7. #include <misctool.h>
  8.  
  9. typedef struct {
  10.     long    blkSize;
  11.     char    identLen;
  12.     char    ident[4];
  13.     int        mscb;
  14.     int        pixPerLine;
  15.     int        palletteCount;
  16.     int        pallette[16];
  17.     int        scanLines;
  18. } infoBlockHdr;
  19.  
  20. typedef struct {
  21.     int        numBytes;
  22.     int        modeWord;
  23. } dirEntry;
  24.  
  25. infoBlockHdr    picHeader = {
  26.     0,    /* size of data block (get's filled in) */
  27.     4, {'M', 'A', 'I', 'N'},
  28.     0,    /* master control word */
  29.     320,    /* pixels per scan line */
  30.     1,        /* number of pallettes */
  31.     {0,0,0,0,0,0,0,0,0,0,0,0,0,0},    /* pallette */
  32.     200        /* # of scan lines */
  33. };
  34.  
  35. CreateRecGS    createblk;
  36. NameRecGS    destroyblk;
  37. OpenRecGS    openblk;
  38. IORecGS        readblk;
  39. IORecGS        writeblk;
  40. RefNumRecGS    closeblk;
  41. SetPositionRecGS setpositionblk;
  42.  
  43. typedef struct {
  44.     word    slices;
  45.     word    width;
  46.     char    image[8 * 11];
  47.     char    mask[8 * 11];
  48.     Point    hotSpot;
  49. } myCursor;
  50.  
  51. #define hotY 0
  52. #define hotX 2
  53.  
  54. static myCursor cursor0 =
  55.     {    11, 4,                                /* 0 */
  56.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  57.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  58.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  59.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  60.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  61.             0x00,0xf0,0xff,0xf0,0x00,0xff,0x00,0x00,
  62.             0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,
  63.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  64.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  65.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  66.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  67.  
  68.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  69.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  70.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  71.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  72.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  73.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  74.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  75.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  76.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  77.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  78.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  79.  
  80.         hotY, hotX };
  81.  
  82. static myCursor cursor1 =
  83.     {    11, 4,                            /* 1 */
  84.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  85.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  86.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  87.             0x00,0x0f,0xf0,0x00,0x0f,0x00,0x00,0x00,
  88.             0x00,0xf0,0x0f,0xf0,0x00,0xf0,0x00,0x00,
  89.             0x00,0xf0,0x00,0xf0,0x00,0xff,0x00,0x00,
  90.             0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,
  91.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  92.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  93.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  94.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  95.  
  96.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  97.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  98.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  99.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  100.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  101.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  102.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  103.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  104.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  105.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  106.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  107.  
  108.         hotY, hotX };
  109.  
  110. static myCursor cursor2 =
  111.     {    11, 4,                            /* 2 */
  112.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  113.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  114.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  115.             0x00,0x0f,0x00,0xf0,0x0f,0x00,0x00,0x00,
  116.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  117.             0x00,0xf0,0x00,0xf0,0x00,0xff,0x00,0x00,
  118.             0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,
  119.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  120.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  121.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  122.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  123.  
  124.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  125.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  126.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  127.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  128.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  129.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  130.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  131.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  132.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  133.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  134.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  135.  
  136.         hotY, hotX };
  137.  
  138. static myCursor cursor3 =
  139.     {    11, 4,                            /* 3 */
  140.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  141.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  142.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  143.             0x00,0x0f,0x00,0x00,0xff,0x00,0x00,0x00,
  144.             0x00,0xf0,0x00,0xff,0x00,0xf0,0x00,0x00,
  145.             0x00,0xf0,0x00,0xf0,0x00,0xff,0x00,0x00,
  146.             0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,
  147.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  148.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  149.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  150.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  151.  
  152.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  153.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  154.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  155.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  156.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  157.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  158.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  159.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  160.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  161.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  162.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  163.  
  164.         hotY, hotX };
  165.  
  166. static myCursor cursor4 =
  167.     {    11, 4,                            /* 4 */
  168.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  169.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  170.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  171.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  172.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  173.             0x00,0xf0,0x00,0xff,0xf0,0xff,0x00,0x00,
  174.             0x00,0xf0,0x00,0x00,0x00,0xf0,0x00,0x00,
  175.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  176.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  177.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  178.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  179.  
  180.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  181.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  182.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  183.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  184.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  185.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  186.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  187.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  188.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  189.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  190.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  191.  
  192.         hotY, hotX };
  193.  
  194. static myCursor cursor5 =
  195.     {    11, 4,                            /* 5 */
  196.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  197.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  198.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  199.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  200.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  201.             0x00,0xf0,0x00,0xf0,0x00,0xff,0x00,0x00,
  202.             0x00,0xf0,0x00,0x0f,0x00,0xf0,0x00,0x00,
  203.             0x00,0x0f,0x00,0x00,0xff,0x00,0x00,0x00,
  204.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  205.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  206.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  207.  
  208.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  209.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  210.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  211.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  212.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  213.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  214.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  215.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  216.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  217.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  218.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  219.  
  220.         hotY, hotX };
  221.  
  222. static myCursor cursor6 =
  223.     {    11, 4,                            /* 6 */
  224.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  225.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  226.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  227.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  228.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  229.             0x00,0xf0,0x00,0xf0,0x00,0xff,0x00,0x00,
  230.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  231.             0x00,0x0f,0x00,0xf0,0x0f,0x00,0x00,0x00,
  232.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  233.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  234.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  235.  
  236.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  237.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  238.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  239.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  240.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  241.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  242.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  243.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  244.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  245.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  246.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  247.  
  248.         hotY, hotX };
  249.  
  250. static myCursor cursor7 =
  251.     {    11, 4,                            /* 7 */
  252.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  253.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  254.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  255.             0x00,0x0f,0x00,0x00,0x0f,0x00,0x00,0x00,
  256.             0x00,0xf0,0x00,0xf0,0x00,0xf0,0x00,0x00,
  257.             0x00,0xf0,0x00,0xf0,0x00,0xff,0x00,0x00,
  258.             0x00,0xf0,0x0f,0x00,0x00,0xf0,0x00,0x00,
  259.             0x00,0x0f,0xf0,0x00,0x0f,0x00,0x00,0x00,
  260.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  261.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  262.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  263.  
  264.         {    0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  265.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  266.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  267.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  268.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  269.             0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
  270.             0x00,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,
  271.             0x00,0x0f,0xff,0xff,0xff,0x00,0x00,0x00,
  272.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  273.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00,
  274.             0x00,0x00,0xff,0xff,0xf0,0x00,0x00,0x00 },
  275.  
  276.         hotY, hotX };
  277.  
  278. static myCursor    *animCursor[8] = {&cursor0,&cursor1,&cursor2,&cursor3,&cursor4,&cursor5,&cursor6,&cursor7};
  279.  
  280.  
  281. int SavePic(pathname, RefPtr)
  282. GSString255    *pathname;
  283. LocInfoPtr    RefPtr;
  284. {
  285.     extern int cTable[16];
  286.  
  287.     char        *invertBuf, *dummyBuf;
  288.     char        *srcptr,*dstptr;
  289.     dirEntry    *ScanLineDirectory;        /* dynamic array */
  290.     unsigned    cursNum = 0;
  291.     unsigned    counter = 0;
  292.     unsigned    linenum, srcSize, dstSize;
  293.     unsigned    lineWidth, numLines;
  294.     unsigned    i;
  295.     int            errNum;
  296.     word        oldSCB;
  297.     long        totalSize;
  298.  
  299.     WaitCursor();
  300.  
  301.     lineWidth = RefPtr->width;    /* get # of bytes per scan line */
  302.     numLines = RefPtr->boundsRect.v2 - RefPtr->boundsRect.v1;    /* # of scan lines */
  303.  
  304.     /* get memory for scan line directory array */
  305.     if(!(ScanLineDirectory = (dirEntry *) malloc(numLines * sizeof(dirEntry))))
  306.         return(0x54);
  307.     
  308.     if(!(dstptr = malloc(lineWidth))) {    /* allocate memory for converted scan line */
  309.         free(ScanLineDirectory);
  310.         return(0x54);        /* return error condition */
  311.     }
  312.     
  313.     if(!(invertBuf = malloc(lineWidth + 160))) {    /* allocate memory for inverted scan line */
  314.         free(dstptr);
  315.         free(ScanLineDirectory);
  316.         return(0x54);        /* return error condition */
  317.     }
  318.     
  319.     destroyblk.pCount = closeblk.pCount = 1;
  320.     destroyblk.pathname = pathname;
  321.     DestroyGS(&destroyblk);
  322.     
  323.     createblk.pCount = 4;
  324.     createblk.pathname = pathname;
  325.     createblk.access = 0xE3;
  326.     createblk.fileType = 0xC0;
  327.     createblk.auxType = 2;
  328.     CreateGS(&createblk);
  329.     if(errNum = /* assignment */ _toolErr)
  330.         goto goodbye2;    /* messy, but efficient! */
  331.  
  332.     openblk.pCount = 3;
  333.     openblk.pathname = pathname;
  334.     openblk.requestAccess = 2;    /* write only */
  335.     OpenGS(&openblk);
  336.     if(errNum = /* assignment */ _toolErr)
  337.         goto goodbye2;
  338.  
  339.     SetMasterSCB((oldSCB = GetMasterSCB()) | 0x0100);    /* make sure cursor doesn't flicker */
  340.  
  341.     setpositionblk.pCount = 3;
  342.     setpositionblk.refNum = closeblk.refNum = openblk.refNum;
  343.     setpositionblk.base = 0;
  344.     setpositionblk.displacement = totalSize = sizeof(picHeader) + (numLines * sizeof(dirEntry));
  345.     /* adjust EOF and mark past header fields of file */
  346.     SetEOFGS(&setpositionblk);
  347.     if(errNum = /* assignment */ _toolErr)
  348.         goto goodbye;    /* messy, but efficient! */
  349.     SetMarkGS(&setpositionblk);
  350.     if(errNum = /* assignment */ _toolErr)
  351.         goto goodbye;    /* messy, but efficient! */
  352.     
  353.     writeblk.pCount = 4;
  354.     writeblk.refNum = openblk.refNum;
  355.     
  356.     srcptr = RefPtr->ptrToPixImage;    /* initialize source pointer */
  357.     writeblk.dataBuffer = dstptr;
  358.     
  359.     for(linenum = 0; linenum < numLines; ++linenum) {
  360.         asm {    /* invert the bytes of the scan line */
  361.             ldy        #0                ; get the # of bytes in the line
  362.             ldx        #0xFFFF            ; inverse mask
  363.             sep        #0x20            ; 8-bit accumulator
  364.         loop:
  365.             txa                        ; put inverse mask into accumulator
  366.             eor        [srcptr],y        ; get the byte and invert it
  367.             sta        [invertBuf],y    ; store in the destination buffer
  368.             iny
  369.             cpy        lineWidth        ; done yet?
  370.             bcc        loop            ; no...
  371. #if 0
  372.             txa                        ; prepare to fill in remainder of scan line
  373.         loop2:
  374.             cpy        #160            ; at least 320 pixels wide?
  375.             bcs        done            ; yes...
  376.             sta        [invertBuf],y    ; else fill it in
  377.             iny
  378.             bra        loop2
  379.         done:
  380. #endif
  381.             rep        #0x20            ; back to 16-bit accumulator
  382.         }
  383.         srcptr += lineWidth;        /* update source pointer */
  384.         srcSize = lineWidth;        /* # of bytes per scan line */
  385.         dummyBuf = invertBuf;        /* use temporary pointer for PackBytes */
  386.         dstSize = PackBytes(&dummyBuf,&srcSize,dstptr,lineWidth);
  387.         totalSize += dstSize;    /* accumulate total size */
  388.         ScanLineDirectory[linenum].numBytes = dstSize;
  389.         ScanLineDirectory[linenum].modeWord = RefPtr->portSCB;
  390.         writeblk.requestCount = dstSize;
  391.         WriteGS(&writeblk);
  392.         if(errNum = /* assignment */ _toolErr)
  393.             goto goodbye;    /* messy, but efficient! */
  394.  
  395.         if(!(++counter & 7)) {    /* update the cursor every eighth scan line processed */
  396.             SetCursor(animCursor[++cursNum]);
  397.             if(!(cursNum < 7))    /* in other words, if cursNum >= 7 (but this produces better code) */
  398.                 cursNum = -1;
  399.         }
  400.     }
  401.     
  402.     setpositionblk.displacement = 0;    /* set file mark to beginning of file */
  403.     SetMarkGS(&setpositionblk);
  404.     if(errNum = /* assignment */ _toolErr)
  405.         goto goodbye;    /* messy, but efficient! */
  406.     
  407.     picHeader.blkSize = totalSize;        /* fill in header fields */
  408.     picHeader.pixPerLine = RefPtr->width << (RefPtr->portSCB ? 2 : 1);    /* pixels per line */
  409.     picHeader.scanLines = numLines;        /* # of lines in image */
  410.     picHeader.mscb = RefPtr->portSCB;    /* master SCB */
  411.  
  412.     /* get the pallette into the header */
  413.     memcpy(picHeader.pallette,cTable,sizeof(picHeader.pallette));
  414.     
  415.     writeblk.requestCount = sizeof(infoBlockHdr);
  416.     writeblk.dataBuffer = (Ptr) &picHeader;
  417.     WriteGS(&writeblk);
  418.     if(errNum = /* assignment */ _toolErr)
  419.         goto goodbye;    /* messy, but efficient! */
  420.     
  421.     writeblk.requestCount = numLines * sizeof(dirEntry);
  422.     writeblk.dataBuffer = (Ptr) ScanLineDirectory;
  423.     WriteGS(&writeblk);
  424.     if(errNum = /* assignment */ _toolErr)
  425.         goto goodbye;    /* messy, but efficient! */
  426.     
  427.     CloseGS(&closeblk);
  428.     errNum = _toolErr;
  429.  
  430. goodbye:
  431.     SetMasterSCB(oldSCB);    /* reset master SCB */
  432.     closeblk.refNum = 0;    /* do a global close */
  433.     CloseGS(&closeblk);
  434. goodbye2:
  435.     free(invertBuf);
  436.     free(dstptr);
  437.     free(ScanLineDirectory);
  438.  
  439.     InitCursor();
  440.  
  441.     return(errNum);
  442. }